package com.wwj.auction.login.controller;

import com.wwj.auction.common.result.R;
import com.wwj.auction.login.entity.Shop;
import com.wwj.auction.login.entity.vo.*;
import com.wwj.auction.login.service.ShopService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 拍品接口
 *
 * @author wwj
 */
@RestController
@RequestMapping("/login/shop")
@Api("商品操作")
public class ShopController {

    @Autowired
    private ShopService shopService;

    /**
     * 获取所有拍品信息
     *
     * @return
     */
    @GetMapping("/list")
    public R list() {
        List<ShopVo> shopVoList = shopService.listToShopVo();
        return R.ok().data("list", shopVoList);
    }

    @GetMapping("/get/images/url")
    public R url() {
        return R.ok().data("url", "https://renren-auction.oss-cn-beijing.aliyuncs.com/shop-test/59ded626Ne3c69b70.jpg");
    }

    /**
     * 发布商品
     *
     * @param shopDetailVo
     * @return
     */
    @PostMapping("/put/shop")
    public R putShop(@RequestBody ShopDetailVo shopDetailVo) {
        shopService.putShop(shopDetailVo);
        return R.ok().message("发布成功");
    }

    /**
     * 分页查询商品信息
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list/{id}/{page}/{limit}")
    public R listForShop(
            @PathVariable("id") Integer id,
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit) {
        PageModel<AuctionListShopVo> pageModel = shopService.listForShop(id, page, limit);
        return R.ok().data("pageModel", pageModel);
    }

    /**
     * 更新拍品的状态
     *
     * @param shopStatus
     * @param shopId
     * @return
     */
    @GetMapping("/status/{shopStatus}/{shopId}")
    public R status(
            @PathVariable("shopStatus") Integer shopStatus,
            @PathVariable("shopId") Integer shopId) {
        shopService.status(shopId, shopStatus);
        return R.ok().message("操作成功");
    }

    /**
     * 获取商品详情页信息
     *
     * @param shopId
     * @return
     */
    @GetMapping("/detail/{shopId}")
    public R detail(@PathVariable("shopId") Integer shopId) {
        ShopDetailTempVo shopDetailTempVo = shopService.detail(shopId);
        return R.ok().data("shopInfo", shopDetailTempVo);
    }

    /**
     * 提供远程调用
     * 扫描已经结束拍卖的商品
     *
     * @return
     */
    @GetMapping("/scan")
    public R scanShop() {
        List<Shop> shopList = shopService.scanShop();
        return R.ok().data("shopList", shopList);
    }
}